package com.wnhoo.smartfishtank.contants.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wnhoo.smartfishtank.R;
import com.wnhoo.smartfishtank.api.data.DataPlug;

import java.util.List;


/**
 * Created by MacBookAir on 15/4/13
 */
public class AdapterPlugScan extends BaseAdapter {

    // 填充数据的list
    public List<DataPlug> list;


    // 上下文
    private Context context;
    // 用来导入布局
    private LayoutInflater inflater = null;
    // 构造器

    private Typeface tf;


    public AdapterPlugScan(List<DataPlug> list, Context context) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);

        //tf = MainActivity.typeface;
        tf = null;
    }

    public void setTypeface(Typeface typeface) {

        this.tf = typeface;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
//        Log.w("AdapterPlugScan", "设备Name:" + list.get(position).getId());
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.listview_item_scan, null);
            holder.bluetooth_scan_dataplug = convertView.findViewById(R.id.bluetooth_scan_dataplug);
//            holder.list_checked = (CheckBox) convertView.findViewById(R.id.checkbox_online);
            holder.list_name = (TextView) convertView.findViewById(R.id.list_name);
//            holder.list_desc = (TextView) convertView.findViewById(R.id.list_desc);
            if (tf != null) {
                holder.list_name.setTypeface(tf);
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String strName = list.get(position).getDes();
        holder.list_name.setText(strName);
        holder.bluetooth_scan_dataplug.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemTimingListener.ItemOnclick(position, v);
            }
        });
        return convertView;
    }

    public final class ViewHolder {
        TextView list_name;
        View  bluetooth_scan_dataplug;
//        TextView list_desc;
//        CheckBox list_checked;
    }
    private OnItemTimingListener onItemTimingListener;

    public void setOnItemTimingListener(OnItemTimingListener l) {
        onItemTimingListener = l;
    }

    public interface OnItemTimingListener {
        boolean ItemOnclick(int position, View view);
    }
}
